#include "pauseview.h"
#include "recource.h"
#include "item/imageitem.h"
#include "view/promptview.h"
#include <QLocale>
enum PauseBtn
{
    CONTINUE_PAUSEB,
    RESTART_PAUSEB,
    BACK_PAUSEB,
    NULL_PAUSEB,
}pauseBtn;

PauseView::PauseView(QWidget *parent) :
    QGraphicsView(parent),
    m_promptview(NULL)
{
    m_Scene = new QGraphicsScene(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setScene(m_Scene);
    m_Scene->setSceneRect(0.0, 0.0, 360.0, 640.0);
    setGeometry(0.0,0.0,360.0,640.0);

    switch(Recource::m_iLanguage)
    {
    case QLocale::Chinese:
    {
        m_mbgItem = new ImageItem(*Recource::m_pausebgImage,
                                 QRect(QPoint(0,0),Recource::m_pausebgImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackImage->size()));
        m_contiueItem = new ImageItem(*Recource::m_pauseContiueImage,
                                 QRect(QPoint(0,0),Recource::m_pauseContiueImage->size()));
        m_contiueItem->setPos(120.0,212.0);
        m_restartItem = new ImageItem(*Recource::m_pauseRestartImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartImage->size()));
    }
        break;
//    case QLocale::HongKong:
    case 255:
    {
        m_mbgItem = new ImageItem(*Recource::m_pausebgHkImage,
                                 QRect(QPoint(0,0),Recource::m_pausebgHkImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackHkImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackHkImage->size()));
        m_contiueItem = new ImageItem(*Recource::m_pauseContiueHkImage,
                                 QRect(QPoint(0,0),Recource::m_pauseContiueHkImage->size()));
        m_contiueItem->setPos(120.0,212.0);
        m_restartItem = new ImageItem(*Recource::m_pauseRestartHkImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartHkImage->size()));
    }
        break;
    default:
    {
        m_mbgItem = new ImageItem(*Recource::m_pausebgEnImage,
                                 QRect(QPoint(0,0),Recource::m_pausebgEnImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackEnImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackEnImage->size()));
        m_contiueItem = new ImageItem(*Recource::m_pauseContiueEnImage,
                                 QRect(QPoint(0,0),Recource::m_pauseContiueEnImage->size()));
        m_contiueItem->setPos(65.0,206.0);
        m_restartItem = new ImageItem(*Recource::m_pauseRestartEnImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartEnImage->size()));
    }
        break;
    }

    m_bgItem = new ImageItem(*Recource::m_promptbgImage,
                             QRect(QPoint(0,0),Recource::m_promptbgImage->size()));
    m_bgItem->setPos(0.0,0.0);
    m_bgItem->setZValue(0.0);
    m_Scene->addItem(m_bgItem);

    m_mbgItem->setPos(0.0,159.0);
    m_mbgItem->setZValue(0.0);
    m_Scene->addItem(m_mbgItem);

    m_contiueItem->setZValue(1.0);
    m_contiueItem->setVisible(false);
    m_Scene->addItem(m_contiueItem);

    m_restartItem->setPos(67.0,296.0);
    m_restartItem->setZValue(1.0);
    m_restartItem->setVisible(false);
    m_Scene->addItem(m_restartItem);

    m_backItem->setPos(67.0,376.0);
    m_backItem->setZValue(1.0);
    m_backItem->setVisible(false);
    m_Scene->addItem(m_backItem);
}

PauseView::~PauseView()
{
    delete m_Scene;
}

void PauseView::mousePressEvent(QMouseEvent *event)
{
    if(m_contiueItem->isUnderMouse())
    {
        m_contiueItem->setVisible(true);
        pauseBtn = CONTINUE_PAUSEB;
    }
    else if(m_restartItem->isUnderMouse())
    {
        m_restartItem->setVisible(true);
        pauseBtn = RESTART_PAUSEB;
    }
    else if(m_backItem->isUnderMouse())
    {
        m_backItem->setVisible(true);
        pauseBtn = BACK_PAUSEB;
    }else
    {
        pauseBtn =NULL_PAUSEB;
    }
}

void PauseView::mouseReleaseEvent(QMouseEvent *event)
{
    switch(pauseBtn)
    {
    case CONTINUE_PAUSEB:
    {
        m_contiueItem->setVisible(false);
        if(m_contiueItem->isUnderMouse())
        {
            emit back(0);
        }
    }
        break;
    case RESTART_PAUSEB:
    {
        m_restartItem->setVisible(false);
        if(m_restartItem->isUnderMouse())
        {
            emit back(1);
        }
    }
        break;
    case BACK_PAUSEB:
    {
        m_backItem->setVisible(false);
        if(m_backItem->isUnderMouse())
        {
            if(m_promptview == NULL)
            {
                m_promptview = new PromptView(this,1);
                m_promptview->showFullScreen();
                connect(m_promptview,SIGNAL(back(int)),this,SLOT(PromptBack(int)));
            }
        }
    }
        break;
    default:
        break;
    }
}

void PauseView::PromptBack(const int &inum)
{
    if(m_promptview != NULL)
    {
        delete m_promptview;
        m_promptview = NULL;
    }
    if(inum == 1)
    {
        back(2);
    }
}
